package com.example.swordjava;



import java.util.ArrayList;
import java.util.HashSet;

public class Test38 {

    public static void main(String[] args) {

        int[][] a = {{1, 2, 3, 4},
                {5, 6, 7, 8},
                {9, 10, 11, 12},
                {13, 14, 15, 16}};

        System.out.println(a[0][1]);

    }

    public class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;

        }
    }

    /**
     * 字符串的排列
     * 输入一个长度为 n 字符串，打印出该字符串中字符的所有排列，你可以以任意顺序返回这个字符串数组。
     */
    public ArrayList<String> Permutation(String str) {
        // write code here
        if (str == null || str.length() == 0) return new ArrayList<>();
        char[] chars = str.toCharArray();
        HashSet<String> set = new HashSet<>();
        dfs(chars, 0, set);
        return new ArrayList<String>(set);
    }

    private void dfs(char[] chars, int i, HashSet<String> set) {

        if (i==chars.length-1){
            set.add(String.valueOf(chars));
        }
        for (int j = i; j < chars.length; j++) {
            swap(i,chars,j);
            dfs(chars,i+1,set);
            swap(i,chars,j);
        }
    }

    private void swap(int i, char[] chars, int j) {
        char temp = chars[j];
        chars[j] = chars[i];
        chars[i] = temp;
    }

}














